home *** CD-ROM | disk | FTP | other *** search
- /*
-
- Ascii 2 JAscii
-
- Converts standard international ASCII text into Japanese ASCII,
- currently supported are JIS, NewJIS, NEC, EUC and Shift-JIS formats.
-
- by Fabrizio Bartoloni <lanch@caribusiness.it>
-
- This source code is freely distributable but I retain the copyright
- on it, you cannot spread modified versions of this source code without
- my permission.
-
- Write me for suggestions, bug reports, improvements, etc.
-
- !BIG! Thanks to: Emiliano "Skywalk3r" Esposito
- Alessandro "Crusher" Gatti
- */
-
- #include <stdio.h>
- #include <stdlib.h>
- #include <string.h>
-
- #define pond "#"
-
- static char verstr[] = "$VER: Ascii2Jascii 1.1k (20.10.00)";
-
- void usage(void)
-
- {
- fprintf(stderr,"\n Where infile is the input file to be converted,\n");
- fprintf(stderr," the destination file will have the same \n");
- fprintf(stderr," name but proper extension according to\n");
- fprintf(stderr," the chosen format [.jis|.njis|.nec|.euc|.sjis].\n\n");
- }
-
- int main (int argc, char **argv)
-
- {
- char *progname = argv[0];
- char buf[256];
- char *destfile = argv[2];
- FILE *fi,*fp;
- char *infile = argv[1];
- char *ins = buf;
- int size;
- int loop;
-
- if (argc != 4)
-
- {
- fprintf(stderr,"\n Ascii2Jascii ©2000 by Fabrizio 'Lanch' Bartoloni\n");
- fprintf(stderr,"\n lanch@caribusiness.it\t lanch@tiscalinet.it\n");
- fprintf(stderr,"\n Usage: %s infile outfile [JIS|NJIS|NEC|EUC|SJIS]\n",progname);
- usage();
- exit(1);
- }
-
- if (fi = fopen(infile,"r")) {
-
- struct tipoheader {
- char *ID; /* Encoding type */
- char *header; /* This header identify the file */
- char *prefix; /* Prefix for each JAscii character */
- char *EndSeq; /* EOF */
- char *space; /* how empty spaces are represented */
- char *punct1, *punct2, *punct3, *punct4, *punct5, *punct6;
- char *punct7, *punct8, *punct9, *punct10, *punct11, *punct12;
- char *punct13, *punct14, *punct15, *punct16, *punct17, *punct18, *punct19;
- char *punct20, *punct21, *punct22, *punct23, *punct24, *punct25, *punct26;
- char *number1, *number2, *number3, *number4, *number5;
- char *number6, *number7, *number8, *number9, *number0;
- int alfa; /* how much the JAscii will be shifted from ASCII */
- };
-
- struct tipoheader codes[] =
- {
- "JIS", "$@", pond, "(J\n", "!!", "!%", "!'", "!(", "!)", "!*", "!@",
- "!A", "!K", "!J", "!N", "!O", "!Q", "!P", "!S", "!R", "!\\", "!]",
- "!a", "!p", "!r", "!s", "!t", "!u", "!v", "!w", "!x", "#1", "#2",
- "#3", "#4", "#5", "#6", "#7", "#8", "#9", "#0", 0,
- "NJIS", "$B", "#", "(J\n", "!!", "!%", "!'", "!(", "!)", "!*", "!@",
- "!A", "!K", "!J", "!N", "!O", "!Q", "!P", "!S", "!R", "!\\", "!]",
- "!a", "!p", "!r", "!s", "!t", "!u", "!v", "!w", "!x", "#1", "#2",
- "#3", "#4", "#5", "#6", "#7", "#8", "#9", "#0", 0,
- "SJIS", "", "", "", "@", "D", "F", "G", "H", "I", "_", "`",
- "j", "i", "m", "n", "p", "o", "r", "q", "{", "|", "m",
- "", "", "", "", "", "", "", "", "P", "Q", "R",
- "S", "T", "U", "V", "W", "X","Z", 32,
- "NEC", "K", pond, "H", "!!", "!%", "!'", "!(", "!)", "!*", "!@",
- "!A", "!K", "!J", "!N", "!O", "!Q", "!P", "!S", "!R", "!\\", "!]",
- "!a", "!p", "!r", "!s", "!t", "!u", "!v", "!w", "!x", "#1", "#2",
- "#3", "#4", "#5", "#6", "#7", "#8", "#9", "#0", 0,
- "EUC", "", "£", "", "¡¡", "¡¥", "¡§", "¡\"", "¡©", "¡ª", "¡À",
- "¡Á", "¡Ë", "¡Ê", "¡Î", "¡Ï", "¡Ñ", "¡Ð", "¡Ó", "¡Ò", "¡Ü",
- "¡Ý", "¡á", "¡ð", "¡ò", "¡ó", "¡ô", "¡õ", "¡ö", "¡÷", "¡ø", "£±",
- "£²", "£³", "£´", "£µ", "£¶", "£·", "£¸", "£¹", "£°", 128
- };
-
- int x; /* position inside the structure */
-
- if ((strcmp(argv[3], "JIS")) == 0)
- {
- x = 0;
- }
- else if ((strcmp(argv[3], "NJIS")) == 0)
- {
- x = 1;
- }
- else if ((strcmp(argv[3], "SJIS")) == 0)
- {
- x = 2;
- }
- else if ((strcmp(argv[3], "NEC")) == 0)
- {
- x = 3;
- }
- else if ((strcmp(argv[3], "EUC")) == 0)
- {
- x = 4;
- }
-
- else {
- fprintf(stderr," Required format is either unknown or unavailable\n");
- exit(1);
- }
-
- if (fp = fopen(destfile,"w")) {
-
- while (fgets(buf,sizeof(buf), fi)) {
- fprintf(fp,"%s",codes[x].header);
- size = strlen(buf);
-
- for (loop = 0;loop < size; loop++)
-
- {
-
- switch (ins[loop])
-
- {
- case ' ' :
- fprintf(fp,"%s", codes[x].space);
- break;
- case '1' :
- fprintf(fp,"%s", codes[x].number1);
- break;
- case '2' :
- fprintf(fp,"%s", codes[x].number2);
- break;
- case '3' :
- fprintf(fp,"%s", codes[x].number3);
- break;
- case '4' :
- fprintf(fp,"%s", codes[x].number4);
- break;
- case '5' :
- fprintf(fp,"%s", codes[x].number5);
- break;
- case '6' :
- fprintf(fp,"%s", codes[x].number6);
- break;
- case '7' :
- fprintf(fp,"%s", codes[x].number7);
- break;
- case '8' :
- fprintf(fp,"%s", codes[x].number8);
- break;
- case '9' :
- fprintf(fp,"%s", codes[x].number9);
- break;
- case '0' :
- fprintf(fp,"%s", codes[x].number0);
- break;
- case '.' :
- fprintf(fp,"%s", codes[x].punct1);
- break;
- case ':' :
- fprintf(fp,"%s", codes[x].punct2);
- break;
- case ';' :
- fprintf(fp,"%s", codes[x].punct3);
- break;
- case '?' :
- fprintf(fp,"%s", codes[x].punct4);
- break;
- case '!' :
- fprintf(fp,"%s", codes[x].punct5);
- break;
- case '\'' :
- fprintf(fp,"%s", codes[x].punct6);
- break;
- case '~' :
- fprintf(fp,"%s", codes[x].punct7);
- break;
- case ')' :
- fprintf(fp,"%s", codes[x].punct8);
- break;
- case '(' :
- fprintf(fp,"%s", codes[x].punct9);
- break;
- case '[' :
- fprintf(fp,"%s", codes[x].punct10);
- break;
- case ']' :
- fprintf(fp,"%s", codes[x].punct11);
- break;
- case '}' :
- fprintf(fp,"%s", codes[x].punct12);
- break;
- case '{' :
- fprintf(fp,"%s", codes[x].punct13);
- break;
- case '>' :
- fprintf(fp,"%s", codes[x].punct14);
- break;
-
- case '<' :
- fprintf(fp,"%s", codes[x].punct15);
- break;
-
- case '+' :
- fprintf(fp,"%s", codes[x].punct16);
- break;
-
- case '-' :
- fprintf(fp,"%s", codes[x].punct17);
- break;
-
- case '=' :
- fprintf(fp,"%s", codes[x].punct18);
- break;
- case '$' :
- fprintf(fp,"%s", codes[x].punct19);
- break;
- case '£' :
- fprintf(fp,"%s", codes[x].punct20);
- break;
- case '%' :
- fprintf(fp,"%s", codes[x].punct21);
- break;
- case '#' :
- fprintf(fp,"%s", codes[x].punct22);
- break;
-
- case '&' :
- fprintf(fp,"%s", codes[x].punct23);
- break;
-
- case '*' :
- fprintf(fp,"%s", codes[x].punct24);
- break;
-
- case '@' :
- fprintf(fp,"%s", codes[x].punct25);
- break;
-
- case '§' :
- fprintf(fp,"%s", codes[x].punct26);
- break;
-
- case '\n' :
- fprintf(fp,"%s", codes[x].EndSeq);
- break;
-
- default :
- fprintf(fp,"%s%c",codes[x].prefix,ins[loop] + codes[x].alfa);
- break;
- } /* endswitch */
- } /* endloop */
-
- } /* endwhile */
-
- } /* endif outfile */
-
- else {
- fprintf(stderr,"unable to create output file: %s\n", destfile);
- exit(1);
- }
-
-
- } /* endif open file */
-
- else {
- fprintf(stderr,"unable to open file: %s!\n",argv[1]);
- exit(1);
- }
-
- fclose(fp);
- fclose(fi);
-
- puts("\n Conversion Done!\n");
- return(0);
- }
-
-